﻿@{
    ViewBag.Title = Model[0].Title;
}

<div class="product-detail mt10">
    <h2 class="product-title">@Model[0].Title</h2>
    <form id="cart-form" class="cart-form" data-ajax="false" method="post" action="#">
        <div class="ui-grid-a p10_0 mt5">
            <div class="ui-block-a ">
                <img alt=""  src="@Model[0].ActualImageUrl" class="product-image" />
            </div>

            <div class="ui-block-b">
                <div class="service_rating ml20 ">
                    <div class="rating fl">
                        <div style="width: 20%;" class="value" rating="TotalBest"></div>
                    </div>
                </div>
                <div class="clear"></div>
                <div class="price f20 mt10 ml20">原价: <u style="color:darkgray">￥@Model[0].MarketPrice</u></div>
                     <div class="price f20 mt10 ml20">销售价: ￥@Model[0].UnitPrice</div>
                <div class="clear"></div>
                <div class="price-delivery mt10 pl25">
                    <div class="viewdesc normalwrap">
                        <ul>
                            <li><span class="red f15">@Model[0].PromotionDescription</span></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="ui-grid-a">
            <div class="ui-block-a mt5">

                <input id="quantity" class="fl mt10" type="number" name="quantity" value="1" min="1" max="30" data-type="range" />
            </div>
            <div class="ui-block-b">

                @if (Model[0].TotalInventory > 0)
                {
                    <a href="#" 
                         onclick="AddToCart()"
                        class="ui-btn-up-f" data-theme="a" data-role="button" >加入购物车</a>
                }
                else
                {
                    <a href="#" data-role="button">暂时缺货</a>
                }

            </div>
        </div>
        <p>
        </p>
        <div class="clear mt20 "></div>
        <span class="product-title green ">@Model[0].LineDescription</span>
        <div class="clear mb20"></div>
        <p></p>
    </form>
</div>
<div data-role="collapsible-set">
    <div class="product-info" data-role="collapsible" data-collapsed="false">
        <h2>规格参数</h2>
        <div class="center product_desc" aria-hidden="false">
            @Html.Raw(@Model[0].DetailSpecification)
        </div>
    </div>
</div>
<div data-role="collapsible-set">
    <div class="product-info" data-role="collapsible">
        <h2>商品实拍</h2>
        <div class="center product_images" aria-hidden="false">
            @foreach (var item in Model[0].ImageList)
            {
                <img src="@item.ImageName" />
            }
        </div>
    </div>
</div>
<div data-role="collapsible-set">
    <div class="product-info" data-role="collapsible" id="product_over">
        <h2>商品描述</h2>
        <div class="product_overview">
            @Html.Raw(@Model[0].Overview)
        </div>
    </div>
</div>
<div data-role="collapsible-set">
    <div class="product-info" data-role="collapsible">
        <h2>用户评价</h2>
        <div class="center product_images" aria-hidden="false">
            <ul class="product_reports" id="ul_product_reports">
                <li>
                    @if (@Model[0].ProductReviewList.Count == 0)
                    {
                        @Html.Raw("暂无评价");
                    }
                    @foreach (var item in @Model[0].ProductReviewList)
                    {
                        <div class="report">
                            <div class="report_title">
                                <div class="avatar">
                                    <img src="http://image5.suning.cn/css/ShoppingArea/V8/images/default50.png" alt="@item.CustomerName - @item.RankName" />
                                    <div class="user_info">
                                        <span class="user_name">@item.CustomerName</span>
                                        <span class="user_level"><span class="gold">@item.RankName</span></span>
                                    </div>
                                </div>
                                <div style="padding-left: 0px;">
                                    <div class="service_rating">
                                        <div class="rating fl">
                                            <div style="width: @item*20 %;" class="value" rating="TotalBest"></div>
                                        </div>
                                        <span class="ml5 fl">@item.InDateFormated</span>
                                    </div>
                                    <div class="clear"></div>
                                </div>
                                <h3>@item.Title</h3>
                            </div>
                            <div class="desc">
                                <p>
                                </p>
                                <dl>
                                    <dt>
                                        <h4>使用心得：</h4>
                                    </dt>
                                    <dd>@item.MeritText</dd>
                                </dl>
                                <dl>
                                    <dt>
                                        <h4>不足：</h4>
                                    </dt>
                                    <dd>@item.FaultsText</dd>
                                </dl>

                                <dl>
                                    <dt>
                                        <h4>优点及建议：</h4>
                                    </dt>
                                    <dd>@item.ImproveText</dd>
                                </dl>
                                <p></p>
                            </div>
                        </div>
                    }

                </li>
            </ul>
        </div>
    </div>
</div>
 <a href="#" onclick="AddFavority(@Model[0].ProductId,@Model[0].MarketPrice,'~/Product/ProductDetail?prd=@Model[0].ProductId')" 
                    data-role="button">添加关注</a>
<script language="javascript" type="text/javascript">
    var AddToCart = function ()
    {
        try {
            var qty = $("#quantity").val();
            KevinShop.Common.ShoppingCart.UpdateToCart('@Model[0].ProductId', qty);
            KevinShop.MessageBox.Success("添加到购物车成功！");
        } catch (e) {
            alert(e);
        }
    }

    var AddFavority = function ($productId, $marketPrice, $returnUrl)
    {
        var $url = "AddFavority?productId=" + $productId + "&marketPrice=" + $marketPrice + "&returnUrl=" + $returnUrl;
        var $result = $.ajax({
            url: $url,
            async: false
        }).responseText;
   
        $result = $.parseJSON($result);

        if ($result.Status == true && $result.ErrorMessage == "ok"){
            KevinShop.MessageBox.Success("关注成功！");
        }
        else if ($result.Status == false && $result.ErrorStatusCode == "404"){
            window.location.href = "../Customer/Login?ReturnUrl=" + $result.ErrorMessage;
        }
        else if ($result.ErrorMessage == "existsProduct"){
            KevinShop.MessageBox.Warning("您已关注过此商品");
        }
        else{
            KevinShop.MessageBox.Warning($result.ErrorMessage);
        }
    }
</script>